﻿using System.IO;

/// <summary>
/// 整形的
/// </summary>
public class EnumField : FieldBase
{
    public EnumField(string className, string desc, string type, string name)
        : base(className, desc, type, name) { }

    public override string F_Type { get { return _className + _name; } }

    /// <summary>
    /// 写入GUI
    /// </summary>
    public override void WriteGUI(int indentLevel, StreamWriter SW)
    {
        string str = "ReflectionTools.SetNonPublicField(data, \"_{0}\", EditorGUILayout.EnumPopup(\"{1}\", ReflectionTools.GetNonPublicField<{2}>(data, \"_{0}\")));".SafeFormat(F_Name, F_Desc, F_Type, F_Name);
        SW.WriteLine(GetIndent(indentLevel) + str);
        //SW.WriteLine(GetIndent(indentLevel) + "_{0} = ({1})EditorGUILayout.EnumPopup(\"{2}\", _{3});".SafeFormat(F_Name, F_Type, F_Desc, F_Name));
    }

    /// <summary>
    /// 写入枚举类型
    /// </summary>
    public override void WriteEnum(int indentLevel, StreamWriter SW)
    {
        string enumStr = GetIndent(indentLevel) + "public enum {0}{1}{2}";
        string enumContent = _type.Substring(_type.IndexOf('{'));
        SW.WriteLine(GetIndent(indentLevel) + "/// <summary> {0}枚举 </summary>".SafeFormat(_desc));
        SW.WriteLine(string.Format(enumStr, _className, _name, enumContent));
        SW.WriteLine(string.Empty);
    }

    /// <summary>
    /// 写入获取数据代码
    /// </summary>
    public override void WriteGetData(int indentLevel, StreamWriter SW, bool isEnd)
    {
        string endStr = isEnd ? string.Empty : ",";
        SW.WriteLine(GetIndent(indentLevel) + "({0})(eReader.GetData(i, \"{1}\").SafeToInt()){2} // {3}".SafeFormat(F_Type, F_Name, endStr, F_Desc));
    }

    public override string ExportDataStr()
    {
        return "((int)data.{0}).ToString()".SafeFormat(F_Name);
    }
}
